package com.javaclimb.music.controller;

import com.alibaba.fastjson.JSONObject;
import com.javaclimb.music.po.Admin;
import com.javaclimb.music.po.Consumer;
import com.javaclimb.music.service.LoginService;
import com.javaclimb.music.utils.Consts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    private LoginService service;

    @RequestMapping(value = "/IsLogin",method = RequestMethod.POST)
    public JSONObject IsLogin(Admin admin) {
        JSONObject jsonObject=new JSONObject();
        boolean b=service.IsLogin(admin);
        if (b){
            jsonObject.put(Consts.CODE,1);
            jsonObject.put(Consts.NAME,"登陆成功");
            return jsonObject;
        }
        jsonObject.put(Consts.CODE,0);
        jsonObject.put(Consts.NAME,"用户名或密码错误");
        return jsonObject;
    }

    @RequestMapping("/CreateAdmin")
    public int CreateAdmin(Admin admin) {
        return service.CreateAdmin(admin);

    }

    @RequestMapping(value = "/IsUserLogin",method = RequestMethod.POST)
    public JSONObject IsUserLogin(Consumer consumer) {
        JSONObject jsonObject=new JSONObject();
        boolean a=service.IsUserLogin(consumer);
        if (a){
            jsonObject.put(Consts.CODE,1);
            jsonObject.put(Consts.NAME,"登陆成功");
            return jsonObject;
        }
        jsonObject.put(Consts.CODE,0);
        jsonObject.put(Consts.NAME,"用户名或密码错误");
        return jsonObject;
    }
}
